package com.mk.es.service.service.imp;

import com.mk.es.service.entity.EsQueryParam;
import com.mk.es.service.entity.imp.ArticleEntity;
import com.mk.es.service.repertory.InterfaceEsRepertory;
import com.mk.es.service.service.IArticleService;
import com.mk.es.service.transport.entity.EsQueryResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 文章业务类
 */
@Service("articleService")
public class ArticleServiceImpl implements IArticleService {
    Logger logger = LoggerFactory.getLogger(ArticleServiceImpl.class);


    @Resource(name = "articleEntityEsRepertory")
    private InterfaceEsRepertory<ArticleEntity> esRepertory;


    /**
     * 添加文章文档
     *
     * @param article
     * @return
     */
    @Override
    public void addArticle(ArticleEntity article) {
        esRepertory.addOrUpdateDocument(article);
    }

    /**
     * 获取文章文档
     *
     * @param id
     * @return
     */
    @Override
    public ArticleEntity getArticle(String id) {
        return esRepertory.getDocument(id);
    }

    /**
     * 更新文章文档
     *
     * @param article
     * @return
     */
    @Override
    public void updateArticle(ArticleEntity article) {
        esRepertory.addOrUpdateDocument(article);
    }

    /**
     * 更新文章文档部分信息
     *
     * @param id
     * @param map
     * @return
     */
    @Override
    public void updateArticlePartInfo(String id, Map<String, Object> map) {
        if (id == null) {
            return;
        }

        esRepertory.updateDocumentPartInfo(id, map);
    }

    /**
     * 删除文章文档
     *
     * @param id
     * @return
     */
    @Override
    public boolean delArticle(String id) {
        return esRepertory.delDocument(id);
    }

    /**
     * 分页获取文档文档
     *
     * @param param
     * @return
     */
    @Override
    public EsQueryResult<ArticleEntity> queryArticle(EsQueryParam param) {
        return esRepertory.querySearch(param);
    }

}
